<template>
	<view class="container">
		<view class="header">
			<view class="bg"></view>
			<image class="logo" :src="this.logo"></image>
			<view class="store-intro">
				<view class="store-name">{{name}}</view>
			</view>
		</view>
		
		<view class="bar">
			<view class="store-item" @click="navTo('/pages/product/list')">
				<text class="yticon icon-shouye"></text>
				<text>全部商品</text>
			</view>

			<view class="store-item" @click="navTo('category')">
				<text class="yticon icon-fenlei1"></text>
				<text>商品分类</text>
			</view>

		</view>
		
		<view class="notice-swiper">
			<swiper class="swiper" 
					indicator-dots="true" 
					indicator-color="rgba(0, 0, 0, .3)" 
					indicator-active-color="#ffffff" 
					autoplay="true"
					interval="3000"
					duration="300"
					previous-margin="60rpx"
					next-margin="60rpx"
					circular="true">
				<swiper-item>
					<view class="swiper-item ">
						<image class="item-image" src="/static/默认商品.png"></image>
					</view>
				</swiper-item>
				<swiper-item>
					<view class="swiper-item ">
						<image class="item-image" src="/static/默认商品.png"></image>
					</view>
				</swiper-item>
				<swiper-item>
					<view class="swiper-item ">
						<image class="item-image" src="/static/默认商品.png"></image>
					</view>
				</swiper-item>
				<swiper-item>
					<view class="swiper-item ">
						<image class="item-image" src="/static/默认商品.png"></image>
					</view>
				</swiper-item>
			</swiper>		
		</view>
		
		<view class="goods-list">
			<view class="tit-box">
				<text class="tit">店铺推荐</text>
			</view>
			<!--<text class="yticon icon-you"></text>-->
		</view>
		
		<view class="goods-section">
			<view 
				v-for="(item, index) in goodsList" :key="index"
				class="goods-item"
				@click="navToDetailPage(item)"
			>
				<view class="image-wrapper">
					<image :src="item.image" mode="aspectFill"></image>
				</view>
				<text class="title clamp">{{item.title}}</text>
				<text class="price">￥{{item.price}}</text>
			</view>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				name: "默认店铺",
				logo: '/static/默认商品.png',
				goodsList: [],
				
				
				
			}
		},
		onLoad(){
			this.localData();
		},
		methods: {
			//请求数据
			async localData(){
				// uni.request({
				// 	url: 'http://47.101.171.217:8080/',
				// 	method: 'GET',
				// 	data: {
						
				// 	},
				// 	success: res => {
				// 		console.log(res)
						
						
				// 	}
				// })
				
				// this.logo = this.$api.json('storeInfo').logo;
				// this.name = this.$api.json('storeInfo').name;
				// this.suscribeNum = this.$api.json('storeInfo').suscribeNum;
				
				let goodsList = await this.$api.json('goodsList');
				this.goodsList = goodsList || [];
			},
			
			susBottonClick(){
				if(this.susOrNot == false){
					this.susOrNot = true;
				}else{
					this.susOrNot = false;
				}
				
			},
			navTo(url){
				uni.navigateTo({  
					url
				})  
			}, 
	
			navToDetailPage(item) {
				//测试数据没有写id，用title代替
				let id = item.title;
				uni.navigateTo({
					url: `/pages/product/product?id=${id}`
				})
			},
		
		}
	}
</script>

<style lang="scss">
	

	%section {
	  display:flex;
	  justify-content: space-around;
	  align-content: center;


	}
	%flex-center {
	 display:flex;
	 flex-direction: column;
	 justify-content: center;
	 align-items: center;
	}
	
	.header{
		background-color: #efefef;
		padding: 20upx 30upx;
		//margin-top: 20upx;
		display: flex;
		
		
		.logo{
			//margin-left: 10upx;
			flex-shrink: 0;
			width: 120upx;
			height: 120upx;
		}
		.store-intro{
			.store-name{
				margin-top: 20rpx;
				margin-left: 30upx;
				font-size: 35upx;
				color: #000;
			}
			
		}
		
		
	}
	.bar{
		@extend %section;

		margin-top: 10upx;
		margin-bottom: 10upx;
		.store-item{
			@extend %flex-center;
			width: 120upx;
			height: 120upx;
			border-radius: 10upx;
			font-size: 30upx;
			color: #ooo;
		}
		.yticon{
			font-size: 48upx;
			margin-bottom: 18upx;
			color: #000;
		}
		.icon-shouhoutuikuan{
			font-size:44upx;
		}
	}
	.notice-wrap {
			margin-top: 10rpx;
			width: 100%;
			height: 300rpx;
		}
		.swiper {
			height: 400rpx;
		}
		.swiper-item {
			display: block;
			line-height: 400rpx;
			text-align: center;
			justify-content: center;
			align-items: center;
		}
	
	.goods-list{
		display:flex;
		align-items:center;
        margin-top: 70rpx;
		height: 50rpx;

		background: linear-gradient(-90deg, rgba(255, 239, 201, 1.0), rgba(220, 81, 153, 1.0));
		
		.tit-box{
			flex: 1;
			display: flex;
			flex-direction: column;
		}
		.tit{
			font-size: $font-lg +2upx;
			color: #fff;
			line-height: 1.3;
			text-align: center;
		}
		.icon-you{
			font-size: $font-lg +2upx;
			color: $font-color-light;
		}
	}
	
	.goods-section{
		display:flex;
		flex-wrap:wrap;
		padding: 0 30upx;
		margin-top: 30rpx;

		.goods-item{
			display:flex;
			flex-direction: column;
			width: 48%;
			padding-bottom: 40upx;
			&:nth-child(2n+1){
				margin-right: 4%;
			}
		}
		.image-wrapper{
			width: 100%;
			height: 330upx;
			border-radius: 3px;
			overflow: hidden;
			
			image{
				width: 100%;
				height: 100%;
				opacity: 1;
			}
		}
		.title{
			font-size: $font-lg;
			color: #000;
			line-height: 80upx;
		}
		.price{
			font-size: $font-lg;
			color: $uni-color-primary;
			line-height: 1;
		}
	}

</style>
